import os
from openai import OpenAI
from pathlib import Path
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
file_object = client.files.create(file=Path("1222167972.pdf"), purpose="file-extract")
file_id = file_object.id
print(file_id)
file_object_2 = client.files.create(file=Path("1222167983.pdf"), purpose="file-extract")
file_id_2 = file_object_2.id
print(file_id_2)
completion = client.chat.completions.create(
    model="qwen-long",
    messages=[
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        # 请将 'file-fe-xxx1' 和 'file-fe-xxx2' 替换为您实际对话场景所使用的 file-id。
        {'role': 'system', 'content': f"fileid://{file_id},fileid://{file_id_2}"},
        {'role': 'user', 'content': '这几篇文章讲了什么？'}
    ],
    stream=True,
    stream_options={"include_usage": True}
)

full_content = ""
for chunk in completion:
    if chunk.choices and chunk.choices[0].delta.content:
        full_content += chunk.choices[0].delta.content
        print(chunk.model_dump())

print({full_content})